clear 
set more off
use "D:\CFPS\cfps2018person_202012"
keep pid fid18 cid18 ///
  qn406 qn407 qn411 qn412 qn414 qn416 qn418 qn420 ///
  qn12016
gen year=2018
cd "D:\Data"
save "2018_depression", replace

clear
set more off
use "D:\CFPS\cfps2020famecon_202306"
cd "D:\Data"
keep fid20 familysize20 fincome1 cyear cmonth 
gen year=2020
merge 1:m fid20 using "D:\CFPS\cfps2020person_202306"
drop if pid==.
save "cfps_2020", replace

clear 
set more off
use "D:\CFPS\cfps2020crossyearid_202312"
cd "D:\Data"

keep pid birthy gender ethnicity entrayear fidbaseline ///
     fid20 ///
     deceased ///
	 marriage_20 cfps2020edu cfps2020sch cfps2020eduy cfps2020eduy_im urban20 hk20r employ20 ///
	 indsurvey20 ///
	 selfrpt20
	 
ren hk20r hk20

sreshape long fid ///
     marriage_ cfps20@edu cfps20@sch cfps20@eduy cfps20@eduy_im ///
	 urban hk employ indsurvey selfrpt, i(pid) j(year) 
ta year
replace year=2000+year
tab year

ren marriage_ marriage
ren (cfps20edu cfps20sch cfps20eduy cfps20eduy_im) (edu sch eduy eduy_im)

tab marriage
des marriage
label value marriage marriage
label define marriage 1 "未婚" 2 "在婚（有配偶）" 3 "同居" 4 "离婚" 5 "丧偶" ///
    -8 "不适用/没有有效数据" -2 "拒绝回答" -1 "不知道"
tab marriage

tab edu
des edu
label value edu edu
label define edu 1 "小学以下" 2 "小学" 3 "初中" 4 "高中" 5 "大专" 6 "大学本科" ///
     7 "硕士" 8 "博士" -9 "缺失" -8 "不适用" -2 "拒绝回答" -1 "不知道"
tab edu

tab sch
des sch 
label value sch sch
label define sch 1 "小学以下" 2 "小学" 3 "初中" 4 "高中" 5 "大专" 6 "大学本科" ///
     7 "硕士" 8 "博士" -9 "缺失" -8 "不适用"
tab sch

tab urban
des urban
label value urban urban
label define urban 0 "乡村" 1 "城镇" -9 "缺失" -8 "不适用" 
tab urban

tab hk
des hk
label value hk hk
label define hk 1 "农业户口" 3 "非农业户口" 5 "没有户口" 7 "居民户口" 79 "不适用(非中国国籍)" ///
      -8 "不适用" -1 "不知道" -2 "拒绝回答"
tab hk

tab employ
des employ
label value employ employ
label define employ 0 "失业" 1 "在业" 3 "退出劳动力市场" -1 "不知道" -8 "不适用" -10 "无法判断"
tab employ

tab indsurvey
des indsurvey
label value indsurvey indsurvey
label define indsurvey -8 "不适用" 0 "无个人问卷" 1 "成人问卷" 2 "少儿问卷" 3 "同时存在个人问卷和少儿家长代答问卷" 4 "只存在个人问卷" 5 "只存在少儿家长代答问卷"
tab indsurvey

tab selfrpt
des selfrpt
label value selfrpt selfrpt
label define selfrpt -8 "不适用" 0 "否" 1 "是"
tab selfrpt

label var year "调查年份"
label var fid "家户ID"
label var indsurvey "调查当年的个人数据集类型"
label var selfrpt "调查当年是否存在个人自答问卷"
label var marriage "调查当年的婚姻状况"
label var edu "调查当年的个人最高学历"
label var sch "调查当年的个人在读/离校阶段学历"
label var eduy "调查当年的个人教育年限"
label var eduy_im "调查当年的个人教育年限-插补值"
label var urban "调查当年的基于国家统计局资料的城乡分类"
label var hk "调查当年的户口状况"
label var employ "调查当年的就业状态"

codebook pid

merge 1:1 pid using "cfps_2020", gen(merge_2)
drop if merge_2==1
ta year
append using "2018_depression"
ta year

save "cfps_20+2018_depression", replace



